package com.googlecode.kipler.container.dl;


/**
 * An implementation of accessibility relations, that are used to connect
 * worlds, in the setting of this tableau algorithm.
 * 
 * @author İnanç Seylan
 * 
 */
public class WorldAccess {
	/**
	 * If an accessibility relation is viewed as an arrow from a world to
	 * another, this is the world on the tail of the arrow.
	 */
	private World from;

	/**
	 * If an accessibility relation is viewed as an arrow from a world to
	 * another, this is the world on the head of the arrow.
	 */
	private World to;

	/**
	 * The relation that connects the worlds
	 */
	private String relation;

	/**
	 * Default constructor
	 */
	public WorldAccess() {

	}

	/**
	 * The constructor that initializes all the fields in this class
	 * 
	 * @param fromWorld
	 *            {@link #fromWorld}
	 * @param toWorld
	 *            {@link #toWorld}
	 * @param relation
	 *            {@link #relation}
	 * @param agent
	 *            {@link #relation}
	 */
	public WorldAccess(World from, World to, String relation) {
		setFrom(from);
		setTo(to);
		setRelation(relation);
	}

	/**
	 * @return the from
	 */
	public World getFrom() {
		return from;
	}

	/**
	 * @param from
	 *            the from to set
	 */
	public void setFrom(World from) {
		this.from = from;
	}

	/**
	 * @return the relation
	 */
	public String getRelation() {
		return relation;
	}

	/**
	 * @param relation
	 *            the relation to set
	 */
	public void setRelation(String relation) {
		this.relation = relation;
	}

	/**
	 * @return the to
	 */
	public World getTo() {
		return to;
	}

	/**
	 * @param to
	 *            the to to set
	 */
	public void setTo(World to) {
		this.to = to;
	}

	/**
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj != null && (obj.getClass().equals(this.getClass()))) {
			WorldAccess other = (WorldAccess) obj;
			return (this.getFrom().equals(other.getFrom())
					&& this.getTo().equals(other.getTo()) && this.getRelation()
					.equals(other.getRelation()));
		}
		return false;
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuffer buffer = new StringBuffer();
		buffer.append("(");
		buffer.append(getFrom().getName());
		buffer.append(" ");
		buffer.append(getRelation());
		buffer.append(" ");
		buffer.append(getTo().getName());
		buffer.append(")");
		return buffer.toString();
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return 17 * 37 + getFrom().hashCode() + getTo().hashCode()
				+ getRelation().hashCode();
	}

}
